<?php

namespace common\logics;

use Yii;
use common\helpers\ArrayHelper;
use common\models\help\Help;

/**
 * H5前端路由模型
 *
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class RouterLogic extends \common\base\Model {

    const SEPARATOR_H5 = '/#/';

    public static function frontend() {
        $frontDomain = ArrayHelper::getValue(Yii::$app->params, 'domain.h5');
        $domain = rtrim($frontDomain, self::SEPARATOR_H5);
        $routes = [
            'home' => 'home',
            'cart' => 'cart',
            'goods' => 'goods/',
            'address' => 'user/address',
            'notice' => 'notice',
            'help' => 'help',
            'rank' => 'rank',
            'license' => 'page/license',
            'privacy_policy' => 'page/privacy_policy',
            'experience' => 'level',
            'title' => 'title',
            'service' => 'service',
            'marking' => 'marking',
            'feedback' => 'feedback',
            'activity' => 'activity',
        ];
        foreach ($routes as $name => $path) {
            $routes[$name] = \common\helpers\Url::h5($path);
        }

        $temps = [
            'cannot.received.sms.code',
        ];
        $systemLinks = Help::findBySystem($temps);
        foreach ($systemLinks as $help) {
            $routes[$help->system] = $help->link['route'];
        }

        return compact('domain', 'routes');
    }

}
